package com.woniuxy.controller;

import com.woniuxy.dto.DataGridView;
import com.woniuxy.dto.MyDto;
import com.woniuxy.pojo.User;
import com.woniuxy.service.CommissionjobService;
import com.woniuxy.vo.CommissionVo;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class CommissionController {
    @Autowired
    private CommissionjobService commissionjobService;
    @GetMapping("/commission.do")
    @ApiOperation(value = "查询订单",httpMethod = "GET",
            protocols = "HTTP",produces = "application/json",
            response = MyDto.class,notes = "查询订单")
    @ResponseBody
    public DataGridView commission(CommissionVo commissionVo){
        Subject subject= SecurityUtils.getSubject();
        Session session=subject.getSession();
        User user=(User)session.getAttribute("USER_SESSION");
        commissionVo.setMuid(user.getId());
        DataGridView res =commissionjobService.findCommissionByuid(commissionVo);
        return res;
    }
// amount 订单金额
    @PostMapping("/commissiontomerchantUser.do")
    @ApiOperation(value = "资金提现",httpMethod = "POST",
            protocols = "HTTP",produces = "application/json",
            response = MyDto.class,notes = "资金提现")
    @ResponseBody
    public MyDto commissiontomerchantUser(String amount){
        //真实姓名 payee_real_name
        // 用户支付宝ID  payee_account
        //订单编号 out_biz_no；
        Subject subject= SecurityUtils.getSubject();
        Session session=subject.getSession();
        User user=(User)session.getAttribute("USER_SESSION");
        Integer id=user.getId();
        MyDto myDto=new MyDto();
        try {
             commissionjobService.commissiontomerchantUser(amount,id);
             myDto.setMsg("提现成功，请稍等资金到账。");
             myDto.setCode(200);
        }catch (Exception e){
            e.printStackTrace();
            myDto.setMsg("提现失败，请稍后再试");
            myDto.setCode(-200);
        }
        return myDto;
    }
}
